package me.raih.controller;

import me.raih.pojo.po.Menu;
import me.raih.pojo.vo.ResultInfo;
import me.raih.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @Author Raih
 * @Time 2020/11/26  14:31
 *
 * 查找菜单 即左侧的菜单条  公共菜单
 */
@Controller
//@RequestMapping(value = "/admin")
public class MenuController {

    @Autowired
    ResultInfo resultInfo;
    @Autowired
    MenuService menuService;

    @RequestMapping(value = "/findMenu",method = RequestMethod.PUT)
    //@ResponseBody
    public void toMenu(HttpSession session){

        List<Map<List<Menu>,List<Menu>>> change;

        //if(Objects.nonNull(session.getAttribute("ADMIN_MENU_FLAG"))){
        //    change = (List<Map<List<Menu>,List<Menu>>>)session.getAttribute("ADMIN_MENU_FLAG");
        //}else {
            change = menuService.menuChange();
        //}
        session.setAttribute("ADMIN_MENU_FLAG",change);
        resultInfo.setData(change);

        resultInfo.setFlag(true);

        //return resultInfo;
    }

    @RequestMapping(value = "/salesFindMenu",method = RequestMethod.PUT)
    //@ResponseBody
    public void toMenu2(HttpSession session){
        List<Map<List<Menu>,List<Menu>>> change;

        //if(Objects.nonNull(session.getAttribute("SALES_MENU_FLAG"))){
        //    change = (List<Map<List<Menu>,List<Menu>>>)session.getAttribute("SALES_MENU_FLAG");
        //}else {
            change = menuService.salesMenuChange();
        //}
        session.setAttribute("SALES_MENU_FLAG",change);
        resultInfo.setData(change);

        resultInfo.setFlag(true);

        //return resultInfo;
    }


}
